package thread.exercise;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-06
 * Time:16:26
 */
public class Exercise2 {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        for (int i = 0; i < 10; i++) {
            System.out.println("hi " + (i + 1));
            Thread.sleep(1000);
            if (i + 1 == 5) {
                t.start();
                t.join();
            }

        }
        System.out.println("主线程结束...");
    }
}
class T extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("hello " + (i + 1));
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("子线程结束...");
    }
}
